package com.example.service.impl;

import com.example.mapper.CountMapper;
import com.example.service.CountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author tong
 * @date 2023/01/20/15:26
 * @description
 */
@Service
public class CountServiceImpl implements CountService {
    @Autowired
    private CountMapper countMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW,isolation = Isolation.READ_COMMITTED)
    @Override
    public void transfer(Integer outUserId, Integer inUserId, Integer money) {
        // 增加
        countMapper.updateMoney(inUserId, money);
        //System.out.println(1/0);
        // 减少
        countMapper.updateMoney(outUserId, -money);
    }
    @Transactional
    @Override
    public void log() {
        System.out.println("记录日志");
        int i = 1/0;
    }
}
